// my/my.js
import {
  InvioceModel
} from '../../../models/invioce'
import {
  Format
} from '../../../utils/common'
const invioceModel = new InvioceModel()
const app = getApp()
let last
const format = new Format()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 0,
    list: [{id: '',name: '',amount: '',recordTime: ''}],
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.invoiceListByUser(0)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.loadMyAccount()
  },
  invoiceListByUser(begin) {
    let vm = this
    invioceModel.invoiceListByUser(begin,8).then(res => {
      console.log(res)
      if (res) {
        if (res.code == '00') {
          if (vm.data.page == 0) {
            vm.setData({
              list: res.invoiceRecords
            })
          } else {
              let list = this.data.list;
              for (let i = 0; i < res.invoiceRecords.length; i++) {
                list.push(res.invoiceRecords[i]);
              }
              vm.setData({
                list,
                show: false
              });            
          }
        } else {
          my.showToast({
            type: 'none',
            content: res.msg,
            duration: 1000,
          });
        }
      }
    })
  },
  scrollMytrip2() {
    try{
      this.setData({ show: true });
      this.data.page = this.data.page + 1
      this.invoiceListByUser(this.data.page)
    } catch(e) {
      this.setData({ show: false });
      console.log('scrollMytrip执行异常:', e);
    }
  },
  toDetail(e) {
    const id = e.currentTarget.dataset.id
    my.navigateTo({
      url: '/pages/invioce/invioceDetail/invioceDetail?id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})